/** 
 * 首页视频的点赞,收藏处理
 * */
 
 
 
 
 
 //获取数据缓存
 function getIndexCache(){
 	var resList = cacheGet(indexList);
 	if (!resList) {
 		var list = new Array(),  //数据数组
 			idstring = ''; //ID字符串集合
 		return {
 			// 数据数组
 			list: list,
 			// 历史ID集合
 			idstr: idstring
 		};
 	}
 	return resList;
 }
 /** 
  * 设置数据缓存
  * one 新数据一个
  * */
 function setIndexCache(one){
 	var resList = getIndexCache();
 	var list = resList.list,  //数据数组
 		idstring = resList.idstr; //历史ID字符串集合
 	if (list.length==0) {
 		idstring = one.videoId;
 	} else {
 		idstring = idstring+','+one.videoId;
 	}
 	list[list.length] = one;
 	var indexNew = {
 		// 数据数组
 		list: list,
 		// 历史ID字符串集合
 		idstr: idstring,
 	};
 	cacheSet(indexList, indexNew);
 }
 // 点赞增加
 function setZanAdd(vid){
 	// 用户信息
 	var userInfo = cacheGet(userInfoKey);
 	var uid = userInfo ? userInfo.uid : 0;
 	// 系统参数
 	var sys = getSys();
 	if (sys.day==0 || sys.appAccess=='') {
 		mui.toast('参数错误',{ 
 			duration:'long', type:'div',
 		});
 		return
 	}
 	// 更新显示
 	var total = mui("#zanInputTotal")[0].value;
 	total = total * 1 + 1;
 	mui("#zanSpan")[0].innerHTML = '<span class="mui-icon-extra mui-icon-extra-heart-filled app-heart-light app-shadow" onclick="setZanDel('+vid+')"></span><input type="hidden" id="zanInputTotal" value="'+total+'"/>';
 	mui("#zanDivTotal")[0].innerHTML = total;
 	mui.toast('你好优秀哦'); 
 	// 更新缓存的赞
 	var resList = getIndexCache();
 	var list = resList.list;
 	if (list.length==0) { return }
 	for (var i=0;i<list.length;i++) {
 		if (list[i].videoId==vid) {
 			list[i].zanTotal = total;
 			list[i].zanUser = 1;
 		}
 	}
 	resList.list = list;
 	cacheSet(indexList, resList);
 	// 更新服务器
 	mui.ajax(sys.domain+'/app/video/zan/add',{
 		data:{
 			appAccess: sys.appAccess,
 			uid:uid,
 			vid: vid
 		},
 		dataType:'json', //服务器返回json格式数据
 		type:'post', //HTTP请求类型
 		timeout:10000, //超时时间设置为10秒
 		headers:{'Content-Type':'application/x-www-form-urlencoded'}, 
 		success:function(res){
 			if (res.code!=0) {
 				// mui.toast('ERR');
 				return
 			}
 			// mui.toast('OK');
 		},
 		error:function(xhr,type,errorThrown){
 			mui.toast('网络错误！',{ 
 				duration:'short', type:'div',
 			});
 		}
 	});
 }
 // 点赞减少
 function setZanDel(vid){
 	// 用户信息
 	var userInfo = cacheGet(userInfoKey);
 	var uid = userInfo ? userInfo.uid : 0;
 	// 系统参数
 	var sys = getSys();
 	if (sys.day==0 || sys.appAccess=='') {
 		mui.toast('参数错误',{ 
 			duration:'long', type:'div',
 		});
 		return
 	}
 	// 更新显示
 	var total = mui("#zanInputTotal")[0].value;
 	total = total * 1 - 1;
 	mui("#zanSpan")[0].innerHTML = '<span class="mui-icon-extra mui-icon-extra-heart-filled app-video-grey app-shadow" onclick="setZanAdd('+vid+')"></span><input type="hidden" id="zanInputTotal" value="'+total+'"/>';
 	mui("#zanDivTotal")[0].innerHTML = total;
 	mui.toast('宝宝伤心了'); 
 	// 更新缓存的赞
 	var resList = getIndexCache();
 	var list = resList.list;
 	for (var i=0;i<list.length;i++) {
 		if (list[i].videoId==vid) {
 			list[i].zanTotal = total;
 			list[i].zanUser = 0;
 		}
 	}
 	resList.list = list;
 	cacheSet(indexList, resList);
 	// 更新服务器
 	mui.ajax(sys.domain+'/app/video/zan/del',{
 		data:{
 			appAccess: sys.appAccess,
 			uid:uid,
 			vid: vid
 		},
 		dataType:'json', //服务器返回json格式数据
 		type:'post', //HTTP请求类型
 		timeout:10000, //超时时间设置为10秒
 		headers:{'Content-Type':'application/x-www-form-urlencoded'}, 
 		success:function(res){
 			// mui.toast('??'+res.code)
 			if (res.code!=0) {
 				// mui.toast('ERR');
 				return
 			}
 			// mui.toast('OK');
 		},
 		error:function(xhr,type,errorThrown){
 			mui.toast('网络错误！',{ 
 				duration:'short', type:'div',
 			});
 		}
 	});
 }
 // 收藏增加
 function setZanAdd(vid){
 	// 用户信息
 	var userInfo = cacheGet(userInfoKey);
 	var uid = userInfo ? userInfo.uid : 0;
 	// 系统参数
 	var sys = getSys();
 	if (sys.day==0 || sys.appAccess=='') {
 		mui.toast('参数错误',{ 
 			duration:'long', type:'div',
 		});
 		return
 	}
 	// 更新显示
 	var total = mui("#collectInputTotal")[0].value;
 	total = total * 1 + 1;
 	mui("#collectSpan")[0].innerHTML = '<span class="mui-icon mui-icon-starhalf app-heart-light app-shadow" onclick="setCollectDel('+vid+')"></span><input type="hidden" id="collectInputTotal" value="'+total+'"/>';
 	mui("#collectDivTotal")[0].innerHTML = total;
 	mui.toast('太棒了'); 
 	// 更新缓存的收藏
 	var resList = getIndexCache();
 	var list = resList.list;
 	if (list.length==0) { return }
 	for (var i=0;i<list.length;i++) {
 		if (list[i].videoId==vid) {
 			list[i].collectTotal = total;
 			list[i].collectUser = 1;
 		}
 	}
 	resList.list = list;
 	cacheSet(indexList, resList);
 	// 更新服务器
 	mui.ajax(sys.domain+'/app/video/collect/add',{
 		data:{
 			appAccess: sys.appAccess,
 			uid:uid,
 			vid: vid
 		},
 		dataType:'json', //服务器返回json格式数据
 		type:'post', //HTTP请求类型
 		timeout:10000, //超时时间设置为10秒
 		headers:{'Content-Type':'application/x-www-form-urlencoded'}, 
 		success:function(res){
 			if (res.code!=0) {
 				// mui.toast('ERR');
 				return
 			}
 			// mui.toast('OK');
 		},
 		error:function(xhr,type,errorThrown){
 			mui.toast('网络错误！',{ 
 				duration:'short', type:'div',
 			});
 		}
 	});
 }
 // 收藏减少
 function setZanDel(vid){
 	// 用户信息
 	var userInfo = cacheGet(userInfoKey);
 	var uid = userInfo ? userInfo.uid : 0;
 	// 系统参数
 	var sys = getSys();
 	if (sys.day==0 || sys.appAccess=='') {
 		mui.toast('参数错误',{ 
 			duration:'long', type:'div',
 		});
 		return
 	}
 	// 更新显示
 	var total = mui("#collectInputTotal")[0].value;
 	total = total * 1 - 1;
 	mui("#collectSpan")[0].innerHTML = '<span class="mui-icon mui-icon-starhalf app-video-grey app-shadow" onclick="setCollectAdd('+vid+')"></span><input type="hidden" id="collectInputTotal" value="'+total+'"/>';
 	mui("#collectDivTotal")[0].innerHTML = total;
 	mui.toast('宝宝心酸'); 
 	// 更新缓存的收藏
 	var resList = getIndexCache();
 	var list = resList.list;
 	for (var i=0;i<list.length;i++) {
 		if (list[i].videoId==vid) {
 			list[i].collectTotal = total;
 			list[i].collectUser = 0;
 		}
 	}
 	resList.list = list;
 	cacheSet(indexList, resList);
 	// 更新服务器
 	mui.ajax(sys.domain+'/app/video/collect/del',{
 		data:{
 			appAccess: sys.appAccess,
 			uid:uid,
 			vid: vid
 		},
 		dataType:'json', //服务器返回json格式数据
 		type:'post', //HTTP请求类型
 		timeout:10000, //超时时间设置为10秒
 		headers:{'Content-Type':'application/x-www-form-urlencoded'}, 
 		success:function(res){
 			// mui.toast('??'+res.code)
 			if (res.code!=0) {
 				// mui.toast('ERR');
 				return
 			}
 			// mui.toast('OK');
 		},
 		error:function(xhr,type,errorThrown){
 			mui.toast('网络错误！',{ 
 				duration:'short', type:'div',
 			});
 		}
 	});
 }